<?php
class model_logs extends common_model {
	/**
	 * 基本表属性
	 */
	protected $table = 'logs';
	protected $pk = 'log_id';
	
	/**
	 * __contruct 初始化
	 * @param string $body 日志内容
	 */
	public function __construct($body = '') {
		//parent
		parent::__construct();
		
		//如果内容不为空则写入日志
		if(!empty($body)) {
			$this->write($body);
		}
	}
	
	/**
	 * 记录一条日志
	 * @param string $body 日志内容
	 */
	public function write($body = 'empty') {
		$data = array();
		$data['create_time'] = time();
		$data['ip'] = $_SERVER['REMOTE_ADDR'];
		$data['model'] = empty($_GET['m']) ? '-' : $_GET['m'];
		$data['action'] = empty($_GET['a']) ? '-' : $_GET['a'];
		$data['body'] = $body;

		$this->create($data);
	}
}
?>
